<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<script>

<!--  客户需求：先获取姓名，然后获取性别，然后获取年龄，最终将三个值拼接到一个数组当中-->

async function getUserData() {
  //第一步，获取姓名
  const user = await new Promise((resolve, reject)=>{
    try {
      // throw Error('获取姓名失败!!')
      setTimeout(()=>{
        console.log('获取姓名成功~~')
        const user = {
          userName : 'wdh'
        }
        resolve(user)
      },1500)

    }catch (e){
      reject(e.message)
    }
  })
//  第二部 获取性别
  const sex = await new Promise((resolve, reject)=>{
    try {
      // throw Error('获取性别失败!!')
      setTimeout(()=>{
        console.log('获取性别成功~~')
        const sex = {
          sex : 'man'
        }
        resolve({
          ...user,
          ...sex
        })
      },1500)

    }catch (e){
      reject(e.message)
    }
  })
  const age = await new Promise((resolve, reject)=>{
    try {
      // throw Error('获取年龄失败!!')
      setTimeout(()=>{
        console.log('获取年龄成功~~')
        const age = {
          age : 18
        }
        resolve({
          ...sex,
          ...age
        })
      },1500)

    }catch (e){
      reject(e.message)
    }
  })
  console.log('最终完整的数据',age)
}
//最终输出完整数据
const result = getUserData()
console.log('result',result)



</script>

</body>
</html>